﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using NUnit.Framework;

using Boggle;

namespace Boggle.Tests
{
    class TestTwoDimensionalArrayExtensions
    {
        [Test, TestCaseSource("GetForEachCases")]
        public void TestForEach(Int32[,] array, Func<List<Int32>, Action<Int32>> actionProducer, List<Int32> expectedCalls)
        {
            var actualCalls = new List<Int32>();
            var action = actionProducer(actualCalls);
            array.ForEach(action);
            CollectionAssert.AreEqual(expectedCalls, actualCalls);
        }

        private IEnumerable<ITestCaseData> GetForEachCases()
        {
            yield return new TestCaseData(
                null,
                new Func<List<Int32>, Action<Int32>>(l => i => l.Add(i)),
                null)
                .Throws<ArgumentNullException>();

            yield return new TestCaseData(
                new Int32[3, 3] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } },
                new Func<List<Int32>, Action<Int32>>(l => null),
                null)
                .Throws<ArgumentNullException>();

            yield return new TestCaseData(
                new Int32[3, 3] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } },
                new Func<List<Int32>, Action<Int32>>(l => i => l.Add(i)),
                new List<Int32> { 1, 2, 3, 4, 5, 6, 7, 8, 9 });
        }
    }
}
